<#assign className = table.className>
<#assign classNameLower = className?uncap_first>
package ${basepackage}.${moduleName}.entity;

import javax.persistence.*;
import org.apache.commons.lang3.builder.*;
import java.math.BigDecimal;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotBlank;
import javax.validation.constraints.NotNull;

/**
 * ${table.remarks}(实体类)
 * Author: Generator
 * Version: 1.0.0
 * Date: 2018/1/17 23:55
 * Gitee: https://gitee.com/rexfang/
 * Email: fangruitao.work@foxmail.com
 * Blog: https://www.cnblogs.com/rexfang/
 */
@Entity
@Table(name = "${table.sqlName}" )
public class ${className} {
	<#list table.columns as column>
	public static final String ${column.constantName} = "${column.columnNameLower}";
	</#list>

	<#list table.columns as column>
	/** ${column.sqlName?upper_case} - ${column.columnAlias} */
	 <#if column.pk>
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	   <#else>
		<#if column.isStringColumn>
		 <#if !column.nullable>
	@NotBlank(message = "${column.columnAlias?replace(" ", "")}不能为空")
		 </#if>
	@Length(max = ${column.size}, message = "${column.columnAlias?replace(" ", "")}长度不能超过${column.size}个字符")
		 <#elseif (column.isNumberColumn || column.isDateTimeColumn) && !column.nullable>
	@NotNull(message = "${column.columnAlias?replace(" ", "")}不能为空")
		</#if>
	 </#if>
    @Column(name = "${column.sqlName?upper_case}", unique = ${column.unique?string}, nullable = ${column.nullable?string}, insertable = true, updatable = true, length = ${column.size})
	private ${column.javaType} ${column.columnNameLower};
	</#list>

<@generateConstructor className/>
<@generateJavaColumns/>
<#macro generateJavaColumns>
<#list table.columns as column>

	public void set${column.columnName}(${column.javaType} value) {
		this.${column.columnNameLower} = value;
	}

	public ${column.javaType} get${column.columnName}() {
		return this.${column.columnNameLower};
	}
</#list>
</#macro>

	@Override
	public String toString() {
		return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
		<#list table.columns as column>
			.append("${column.constantName}",get${column.columnName}())
		</#list>
			.toString();
	}

	@Override
	public int hashCode() {
		return new HashCodeBuilder()
		<#list table.pkColumns as column>
			.append(get${column.columnName}())
		</#list>
			.toHashCode();
	}

	@Override
	public boolean equals(Object obj) {
		<#list table.columns as column>
		<#if column.pk>
		if(this.get${column.columnName}() == null){
			return false;
		}
		</#if>
		</#list>
		if(!(obj instanceof ${className})){
			return false;
		}
		if(this == obj) {
			return true;
		}
		${className} other = (${className})obj;
		return new EqualsBuilder()
			<#list table.pkColumns as column>
			.append(get${column.columnName}(),other.get${column.columnName}())
			</#list>
			.isEquals();
	}
}